package com.cloudsigns.factorymanager2.project.customview;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.engineering.activity.EngineeringInstallStatusTableForManagerActivity1;
import com.cloudsigns.factorymanager2.engineering.activity.EngineeringMainForManagerActivity;
import com.cloudsigns.factorymanager2.engineering.adapter.DropDownPoupWindowAdapter;
import com.cloudsigns.factorymanager2.media_system.activity.MediaSystemMainFragmentActivity;

import java.util.List;

/**
 * Created by tony on 2017/12/2.
 */

public class DropDownPoupWindow extends PopupWindow {
    private Context mcontext;
    private View conentView;
    private View.OnClickListener mClickListener;
    private String tag;
    private int functionTag;
    private DropDownPoupWindowAdapter dropDownPoupWindowAdapter;


    public DropDownPoupWindow(Activity context, String tag, int functionTag, int layoutId, int width, int height) {
        super(context);
        this.mcontext = context;
        this.tag = tag;
        this.functionTag = functionTag;
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        conentView = inflater.inflate(layoutId, null);
        // 设置SelectPicPopupWindow的View
        this.setContentView(conentView);
        // 设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(width);
        // 设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(height);
        // 设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        this.setOutsideTouchable(true);
        // 刷新状态
        this.update();
        // 实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0000000000);
        // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ，设置其他控件变化等操作
        this.setBackgroundDrawable(dw);
        // mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);
        // 设置SelectPicPopupWindow弹出窗体动画效果
        // this.setAnimationStyle(R.style.AnimationPreview);


    }


    /**
     * 显示popupWindow
     *
     * @param anchor
     * @param xoff
     * @param yoff
     */
    public void showPopupWindow(View anchor, int xoff, int yoff) {
        if (!this.isShowing()) {
            // 以下拉方式显示popupwindow
            this.showAsDropDown(anchor, xoff, yoff);// 显示popupwindow的位置
        } else {
            this.dismiss();
        }
    }

    public void setCusOnDismissListener(OnDismissListener dismissListener) {

        setOnDismissListener(dismissListener);
    }

    public void setOnClickListener(View.OnClickListener mClickListener) {
        this.mClickListener = mClickListener;

        if (null != tag) {
            if (tag.equals("CreateEngineeringOrderListActivity")) {
//        tv_design_order = conentView.findViewById(R.id.tv_design_order);
//        tv_production_task_order = conentView.findViewById(R.id.tv_production_task_order);
                TextView tv_engineering_installation_order = conentView.findViewById(R.id.tv_engineering_installation_order);
                TextView tv_engineering_construct_order = conentView.findViewById(R.id.tv_engineering_construct_order);
                TextView tv_batch_installation_order = conentView.findViewById(R.id.tv_batch_installation_order);
                TextView tv_publication = conentView.findViewById(R.id.tv_publication);
                TextView tv_patrol = conentView.findViewById(R.id.tv_patrol);
                TextView tv_xinachangkancha = conentView.findViewById(R.id.tv_xinachangkancha);
                TextView tv_weixiu = conentView.findViewById(R.id.tv_weixiu);
//                TextView tv_maintenance_order = conentView.findViewById(R.id.tv_maintenance_order);


                //        tv_design_order.setOnClickListener(mClickListener);
//        tv_production_task_order.setOnClickListener(mClickListener);
                tv_engineering_installation_order.setOnClickListener(mClickListener);
                tv_engineering_construct_order.setOnClickListener(mClickListener);
                tv_batch_installation_order.setOnClickListener(mClickListener);
                tv_publication.setOnClickListener(mClickListener);
                tv_patrol.setOnClickListener(mClickListener);
                tv_xinachangkancha.setOnClickListener(mClickListener);
                tv_weixiu.setOnClickListener(mClickListener);
//                tv_maintenance_order.setOnClickListener(mClickListener);

            } else if (tag.equals("EngineeringMainForSuperActivity")) {

                RelativeLayout rl_intelligent_control = conentView.findViewById(R.id.rl_intelligent_control);
                RelativeLayout rl_maintenance_operation = conentView.findViewById(R.id.rl_maintenance_operation);
                RelativeLayout rl_engineering_management = conentView.findViewById(R.id.rl_engineering_management);

                rl_intelligent_control.setOnClickListener(mClickListener);
                rl_maintenance_operation.setOnClickListener(mClickListener);
                rl_engineering_management.setOnClickListener(mClickListener);

            } else if (tag.equals("EngineeringMainForManagerActivity") || tag.equals("ProjectMapActivity")) {
                switch (functionTag) {
                    case EngineeringMainForManagerActivity.MODULE:
                        LinearLayout rl_engineering_management = conentView.findViewById(R.id.ll_engineering_management);
                        LinearLayout rl_track = conentView.findViewById(R.id.ll_track);
                        LinearLayout rl_intelligent_control = conentView.findViewById(R.id.ll_intelligent_control);
                        LinearLayout ll_achievement = conentView.findViewById(R.id.ll_achievement);
                        LinearLayout rl_gongxu = conentView.findViewById(R.id.ll_gongxu);

                        rl_engineering_management.setOnClickListener(mClickListener);
                        rl_track.setOnClickListener(mClickListener);
                        rl_intelligent_control.setOnClickListener(mClickListener);
                        ll_achievement.setOnClickListener(mClickListener);
                        rl_gongxu.setOnClickListener(mClickListener);

                        break;
                    case EngineeringMainForManagerActivity.ENGINEERING:
                        LinearLayout rl_engineering_installation = conentView.findViewById(R.id.ll_engineering_installation);
                        LinearLayout rl_engineering_construct = conentView.findViewById(R.id.ll_engineering_construct);
                        LinearLayout rl_batch_engineering = conentView.findViewById(R.id.ll_batch_engineering);
                        LinearLayout rl_maintenance = conentView.findViewById(R.id.ll_maintenance);
                        LinearLayout rl_publication = conentView.findViewById(R.id.ll_publication);
                        LinearLayout rl_patrol = conentView.findViewById(R.id.ll_patrol);


                        rl_engineering_installation.setOnClickListener(mClickListener);
                        rl_engineering_construct.setOnClickListener(mClickListener);
                        rl_batch_engineering.setOnClickListener(mClickListener);
                        rl_maintenance.setOnClickListener(mClickListener);
                        rl_publication.setOnClickListener(mClickListener);
                        rl_patrol.setOnClickListener(mClickListener);
                        break;
                    case EngineeringMainForManagerActivity.SELECT_PROJECT:
                        break;
                }
            } else if (tag.equals("EngineeringInstallStatusTableForManagerActivity1")) {

                switch (functionTag) {
                    case EngineeringInstallStatusTableForManagerActivity1
                            .MODULE_STATU:

                        break;
                    case EngineeringInstallStatusTableForManagerActivity1.MODULE_SELECT:
                        break;

                }


            } else if (tag.equals("EngineeringManagerStatusTableActivity")) {

                LinearLayout ll_engineering_installation = conentView.findViewById(R.id.ll_engineering_installation);
                LinearLayout ll_engineering_construct = conentView.findViewById(R.id.ll_engineering_construct);
                LinearLayout ll_batch_engineering = conentView.findViewById(R.id.ll_batch_engineering);
                LinearLayout ll_publication = conentView.findViewById(R.id.ll_publication);
                LinearLayout ll_maintenance = conentView.findViewById(R.id.ll_maintenance);
                LinearLayout ll_survey = conentView.findViewById(R.id.ll_survey);
                LinearLayout ll_patrol = conentView.findViewById(R.id.ll_patrol);

                ll_engineering_installation.setOnClickListener(mClickListener);
                ll_engineering_construct.setOnClickListener(mClickListener);
                ll_batch_engineering.setOnClickListener(mClickListener);
                ll_publication.setOnClickListener(mClickListener);
                ll_maintenance.setOnClickListener(mClickListener);
                ll_survey.setOnClickListener(mClickListener);
                ll_patrol.setOnClickListener(mClickListener);
            }




            /*媒体运维系统*/
            else if (tag.equals("MediaSystemMainFragmentActivity")){
                switch (functionTag) {
                    case MediaSystemMainFragmentActivity.MODULE1:
                        LinearLayout ll_intelligent_device = conentView.findViewById(R.id.ll_intelligent_device);
                        LinearLayout ll_publication = conentView.findViewById(R.id.ll_publication);
                        LinearLayout ll_construction = conentView.findViewById(R.id.ll_construction);

                        ll_intelligent_device.setOnClickListener(mClickListener);
                        ll_publication.setOnClickListener(mClickListener);
                        ll_construction.setOnClickListener(mClickListener);
                        break;

                    case MediaSystemMainFragmentActivity.MODULE2:
                        LinearLayout ll_construct = conentView.findViewById(R.id.ll_construct);
                        LinearLayout ll_publication2 = conentView.findViewById(R.id.ll_publication2);
                        LinearLayout ll_maintenance2 = conentView.findViewById(R.id.ll_maintenance2);
                        LinearLayout ll_service = conentView.findViewById(R.id.ll_service);

                        ll_construct.setOnClickListener(mClickListener);
                        ll_publication2.setOnClickListener(mClickListener);
                        ll_maintenance2.setOnClickListener(mClickListener);
                        ll_service.setOnClickListener(mClickListener);
                        break;

                    case MediaSystemMainFragmentActivity.MODULE3:
                        break;
                }
            }

            /*运维-运营层*/
            else if (tag.equals("OperateMaintainFragmentActivity")){
                switch (functionTag) {
                    case MediaSystemMainFragmentActivity.MODULE1:
                        LinearLayout ll_duty_control = conentView.findViewById(R.id.ll_duty_control);
                        LinearLayout ll_duty_inspection = conentView.findViewById(R.id.ll_duty_inspection);
                        LinearLayout ll_publication = conentView.findViewById(R.id.ll_publication);
                        LinearLayout ll_construction = conentView.findViewById(R.id.ll_construction);

                        ll_duty_control.setOnClickListener(mClickListener);
                        ll_duty_inspection.setOnClickListener(mClickListener);
                        ll_publication.setOnClickListener(mClickListener);
                        ll_construction.setOnClickListener(mClickListener);
                        break;

                    case MediaSystemMainFragmentActivity.MODULE2:
                        LinearLayout ll_work_plan2 = conentView.findViewById(R.id.ll_work_plan2);
                        LinearLayout ll_duty_inspection2 = conentView.findViewById(R.id.ll_duty_inspection2);
                        LinearLayout ll_publication2 = conentView.findViewById(R.id.ll_publication2);
                        LinearLayout ll_maintenance2 = conentView.findViewById(R.id.ll_maintenance2);
                        LinearLayout ll_service2 = conentView.findViewById(R.id.ll_service2);
                        LinearLayout ll_construction2 = conentView.findViewById(R.id.ll_construction2);

                        ll_work_plan2.setOnClickListener(mClickListener);
                        ll_duty_inspection2.setOnClickListener(mClickListener);
                        ll_publication2.setOnClickListener(mClickListener);
                        ll_maintenance2.setOnClickListener(mClickListener);
                        ll_service2.setOnClickListener(mClickListener);
                        ll_construction2.setOnClickListener(mClickListener);
                        break;

                    case MediaSystemMainFragmentActivity.MODULE3:
                        break;
                }
            }

        }

    }


}
